﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using PocketApplicationsMVC.Managers;

namespace PocketApplicationsMVC.Views
{
    public class MenuController : IController
    {
        private IMenuView view;

        #region IController Members

        public IView View
        {
            get
            {
                return view;
            }
            set
            {
                view = (IMenuView)value;
                AttachView(view);
            }
        }

        #endregion

        public MenuController(IMenuView view)
        {
            this.view = view;
            this.AttachView(this.view);
        }

        private void AttachView(IMenuView iMenuView)
        {
            // hook up to views events
            view.SelectedApplication += new EventHandler<PocketApplicationArgs>(view_SelectedApplication); 
            //new EventHandler(view_SelectedApplication);
            view.Exit+=new EventHandler(view_Exit);
        }

        void view_SelectedApplication(object sender, PocketApplicationArgs e)
        {
            view.UpdateText("selected application " + e.Application.ToString());
            switch (e.Application)
            {
                case EnumApplication.BoxNet:
                    //BoxNetForm form = ApplicationManager.Instance.GetBoxNetForm();
                    ApplicationManager.Instance.ShowBoxNetForm();
                    view.Hide();
                    break;
                default:
                    break;
            }
        }

        void view_Exit(object sender, EventArgs e)
        {
            Application.Exit();
        }

    }
}
